//
//  MyShareListVC.m
//  shortvideoplay
//
//  Created by adam on 2024/9/29.
//

#import "MyShareListVC.h"
#import "JXCategoryTitleView.h"
#import "JXCategoryView.h"
#import "MyShareJianliListVC.h"
#import "QZInputYaoqingVC.h"
#import "MyShareGuizheVC.h"

@interface MyShareListVC ()<JXCategoryViewDelegate,JXCategoryListContainerViewDelegate,JXCategoryListContentViewDelegate>

@property (weak, nonatomic) IBOutlet UILabel *titleLabel1;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel2;
@property (weak, nonatomic) IBOutlet UILabel *myNumber;
@property (weak, nonatomic) IBOutlet UIButton *fuzhiButton;
@property (weak, nonatomic) IBOutlet UIButton *shareButton;

@property(strong, nonatomic)NSMutableArray * nameArr;
@property (nonatomic, strong) JXCategoryTitleView *myCategoryView;
@property (nonatomic, strong) JXCategoryListContainerView * listContainerView;
@end

@implementation MyShareListVC

- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.myNumber.text = [QZUserInfoModel share].invite_code;
    UIButton *tipButton = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-65, kStatusBarHeight+2, 50, 40)];
    tipButton.backgroundColor = subviewback_black;
    [tipButton setTitle:@"规则" forState:UIControlStateNormal];
    [tipButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    tipButton.titleLabel.font = Font(14);
    tipButton.layer.cornerRadius = 8;

    UIButton * listButton = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-155, kStatusBarHeight+2, 80, 40)];
    listButton.backgroundColor = subviewback_black;
    [listButton setTitle:@"我的邀请人" forState:UIControlStateNormal];
    [listButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    listButton.titleLabel.font = Font(14);
    listButton.layer.cornerRadius = 8;
    listButton.clipsToBounds = YES;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:listButton];
    [listButton addTarget:self action:@selector(listTap) forControlEvents:UIControlEventTouchUpInside];
    [tipButton addTarget:self action:@selector(tipTap) forControlEvents:UIControlEventTouchUpInside];
    

    
    self.navigationItem.rightBarButtonItems = @[[[UIBarButtonItem alloc]initWithCustomView:tipButton],[[UIBarButtonItem alloc]initWithCustomView:listButton]];
    
    
    [self.titleLabel1 setTransform:CGAffineTransformMakeRotation(-0.12)];
    [self.titleLabel2 setTransform:CGAffineTransformMakeRotation(0.12)];
    
    self.fuzhiButton.backgroundColor = MainColor;
    self.fuzhiButton.layer.cornerRadius = 16;
    
    self.shareButton.backgroundColor = MainColor;
    self.shareButton.layer.cornerRadius = 16;
    
    self.myNumber.textColor = MainColor;
    
    
    self.nameArr = [NSMutableArray new];
    [self.nameArr addObject:@"邀请奖励"];
    [self.nameArr addObject:@"开通奖励"];
    
    self.myCategoryView = [[JXCategoryTitleView alloc] init];
    self.myCategoryView.backgroundColor = [UIColor clearColor];
    self.myCategoryView.frame = CGRectMake(0, 100, KScreen_W, 40);
    self.myCategoryView.titleFont = FontMedium(14);
    self.myCategoryView.titleSelectedFont = FontBold(16);
    self.myCategoryView.titles = self.nameArr;
    self.myCategoryView.titleColorGradientEnabled = YES;
    self.myCategoryView.titleColor = COLOR_ALPH(255, 255, 255, 0.77);
    self.myCategoryView.titleSelectedColor = [UIColor whiteColor];
    self.myCategoryView.delegate = self;
    
    self.listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
    self.listContainerView.bounces = YES;
    self.listContainerView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    self.listContainerView.frame = CGRectMake(0, 140, KScreen_W, KScreen_H-KNav_H-140-KSafeAreaBottomHeight);
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:self.listContainerView];
       UILabel * oldshowSSSSTip2 = [[UILabel alloc]init];
    oldshowSSSSTip2.clipsToBounds = YES;
    oldshowSSSSTip2.text = @"kass显示区";
    oldshowSSSSTip2.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip2.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip2.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip2.hidden = YES;
    [self.view addSubview:oldshowSSSSTip2];
    [self.view addSubview:self.myCategoryView];
    self.myCategoryView.contentScrollView = self.listContainerView.scrollView;
    self.myCategoryView.listContainer = self.listContainerView;

}
-(void)listTap{
    if([[QZUserInfoModel share].invite_mid intValue] > 0){
        [YBMsgPop showPop:@"你已填写过邀请码了"];
        return;
    }
    if([Tools intervalSinceNow:[QZUserInfoModel share].createtime]){
        [YBMsgPop showPop:@"你注册超时10天，不能在填写邀请码了"];
        return;
    }
    QZInputYaoqingVC * vc = [[QZInputYaoqingVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
-(void)tipTap{
    MyShareGuizheVC * guizhe = [[MyShareGuizheVC alloc]init];
    [self.navigationController pushViewController:guizhe animated:YES];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
- (IBAction)shareTap:(id)sender {
    //分享
    [Tools iosSystemShare:@[[NSURL URLWithString:SHAREURL]] sourceView:self.view success:^{
        [YBMsgPop showPop:@"分享成功"];
    } fail:^{
        [YBMsgPop showPop:@"分享失败"];
    }];
}

- (IBAction)fuzhiTap:(id)sender {
    UIPasteboard *pab = [UIPasteboard generalPasteboard];
    NSString *string = self.myNumber.text;
    pab.string = string;
    if (pab == nil) {
        [YBMsgPop showPop:@"复制失败"];
    }else{
        [YBMsgPop showPop:@"复制成功"];
    }
}


- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return self.nameArr.count;
}
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
    if(index == 0){
        MyShareJianliListVC *list = [[MyShareJianliListVC alloc] init];
        list.yaoqingType = 0;
        return list;
    }else if(index == 1){
        MyShareJianliListVC *list = [[MyShareJianliListVC alloc] init];
        list.yaoqingType = 1;
        return list;
    }
    return nil;
}
- (BOOL)categoryView:(JXCategoryBaseView *)categoryView canClickItemAtIndex:(NSInteger)index{
    if([QZUserInfoModel isLogin] == NO && index > 0){
        [QZUserInfoModel presentLoginView];
        return NO;
    }else{
        return YES;
    }
}
- (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio{
    if(leftIndex == 0 && [QZUserInfoModel isLogin] == NO){
        categoryView.contentScrollView.contentSize  = CGSizeMake(0, categoryView.contentScrollView.contentSize.height);
    }
}
@end
